package io.github.handyang.algorithms.sort;

public class InsertSortAlgorithms implements SortAlgorithms {

    @Override
    public void sort(int[] arr) {
        if (arr == null || arr.length < 2) return;

        for (int i = 0; i < arr.length; i++) {
            int item = arr[i];

            for (int j = 0; j < i; j++) {
                if (less(item, arr[j])) {
                    for (int k = i; k > j; k--) {
                        arr[k] = arr[k - 1];
                    }

                    arr[j] = item;
                    break;
                }
            }
        }
    }
}
